<?php

require_once('mysql.php');

class User{

        var $id;
	var $pseudo;
	var $mail;
	var $nom;
	var $prenom;
	
	
	public function __construct($id_tmp,$pseudo_tmp,$mail_tmp,$nom_tmp,$prenom_tmp){
		
            $this->id = $id_tmp;
            $this->pseudo = $pseudo_tmp;
            $this->mail = $mail_tmp;
            $this->nom = $nom_tmp;
            $this->prenom = $prenom_tmp;
	}
	
	public function toJSON(){
		
		return "{'pseudo':'$this->pseudo','mail':'$this->mail','nom':'$this->nom','prenom':'$this->prenom'}";
	}
        
       public function isAdmin(){
           $result;
           $sql;
           $bdd = new Mysql();

           $sql="SELECT * FROM admin WHERE admin.id='".$this->id."'";
            //on vérifie si la requete est bien envoyée
            if( !$result = $bdd -> Send_Query($sql) ) {
                     die($bdd -> return_error());
            }else

            //on verifie que l'utilisateur existe bien dans la table admin, si 0 resultats l'utilisateur nest pas un admin
            if($bdd->num_rows()==0){
                $bdd->close();
                return false;
            }else{
                 $bdd->close();
                 return true;
            }
	}
        
        public function getUsageName(){
            if($this->getPrenom()== null || $this->getNom()==null)
                    return $this->pseudo;
            else 
                return $this->getPrenom ()." ".$this->getNom ();
        }
        
        public function getId() {
            return $this->id;
        }

        public function getPseudo() {
            return $this->pseudo;
        }

        public function getMail() {
            return $this->mail;
        }

        public function getNom() {
            return $this->nom;
        }

        public function getPrenom() {
            return $this->prenom;
        }
        
        public function disable(){
            $result;
           $sql;
           $bdd = new Mysql();
           
           $sql="UPDATE user set active='FALSE' where id=".$this->id;
           if ($bdd->Send_Query($sql)){
               return true;
           }
           else
               return false;
        }



}
?>